package cn.explink.dop.gis;

import java.util.ArrayList;
import java.util.List;

public class Cluster implements Comparable<Cluster> {
	private Center center;
	private List<Point> pointList = new ArrayList<Point>();

	public Cluster() {
		super();
	}

	public Cluster(Center center, List<Point> pointList) {
		super();
		this.center = center;
		this.pointList = pointList;
	}

	public void add(Point point) {
		int oriLength = this.pointList.size(); // 当前中心点
		Center oriCenter = new Center(0, 0);
		if (this.center != null) {
			oriCenter.setLng(this.center.getLng() * oriLength);
			oriCenter.setLat(this.center.getLat() * oriLength);
		}
		oriCenter.setLng((oriCenter.getLng() + point.getLng()) / (oriLength + 1));
		oriCenter.setLat((oriCenter.getLat() + point.getLat()) / (oriLength + 1));
		this.center = oriCenter;
		this.pointList.add(point);
	}

	public Center getCenter() {
		return this.center;
	}

	public void setCenter(Center center) {
		this.center = center;
	}

	public List<Point> getPointList() {
		return this.pointList;
	}

	public void setPointList(List<Point> pointList) {
		this.pointList = pointList;
	}

	@Override
	public int compareTo(Cluster cluster) {
		if (this.pointList.size() > cluster.getPointList().size()) {
			return 1;
		} else if (this.pointList.size() == cluster.getPointList().size()) {
			return 0;
		} else {
			return -1;
		}
	}

}
